/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package actioncombination.common.value;

import actioncombination.common.datastructure.Pair;

/**
 *
 * @author Administrador
 */
public class Point2DDoubleValue extends Value<Pair<Double, Double>> {
	private double x, y;

	private String string;

	public Point2DDoubleValue(double x, double y) {
		this.x = x;
		this.y = y;
		string = "<" + String.format("%.4f", x) + ", "
				+ String.format("%.4f", y) + ">";
	}

	@Override
	public String toString() {
		return string;
	}

	public double getX() {
		return x;
	}

	public double getY() {
		return y;
	}

	@Override
	public boolean equals(Object object) {
		if (object instanceof Point2DDoubleValue) {
			return string.equals(object.toString());
		}
		return false;
	}

	@Override
	public int hashCode() {
		return string.hashCode();
	}

	public static boolean isWithinThreshold(Point2DDoubleValue position,
			Point2DDoubleValue reference, DoubleValue threshold) {
		return (position.x - reference.x) * (position.x - reference.x)
				+ (position.y - reference.y) * (position.y - reference.y) < threshold
				.getValue()
				* threshold.getValue();
	}

    public Pair<Double, Double> getValue() {
        return new Pair<Double, Double>(this.getX(), this.getY());
    }

    public int compareTo(Pair<Double, Double> o) {
        //CHOCHO        
        return Double.compare(o.getFirst(), o.getSecond());
    }

}

